﻿@page "/gantt-chart/editing"

@using Syncfusion.Blazor.Gantt
@using BlazorDemos
@using ej2_blazor_ganttdata

@inherits SampleBaseComponent;

<SampleDescription>
    <p>
        This sample demonstrates the various phases involved in constructing a residential house, from testing the soil to handing over the fully constructed property to the owner. This also demonstrates CRUD operations in a Gantt Chart.You can perform CRUD operations as follows,
        <li><code>Add</code> - To add new task, click Add toolbar button</li>
        <li><code>Edit </code>- To edit a task, double click a row or double click a taskbar or click toolbar Edit button after selected a row </li>
        <li><code>Indent</code> - To indent a task, click toolbar indent button after selecting a row</li>
        <li><code>Outdent </code> - To outdent a task, click toolbar outdent button after selecting a row</li>
        <li><code>Delete</code> - To delete a task, click toolbar Delete button after selected a row</li>
        <li><code>Update,Cancel</code> - You can save or discard changes by click toolbar Update and Cancel button respectively </li>
    </p>
</SampleDescription>
<ActionDescription>
    <p>
        This CRUD operations can be configured in Gantt Chart using <code>EditSettings</code> and <code>AllowTaskbarEditing</code>. Gantt Chart has two modes to manipulate the datasource
        <li><code>Auto</code></li>
        <li><code>Dialog</code></li>
        In this demo, <code>Auto</code> mode is enabled for editing. On the TreeGrid side, you can start editing any row by double
        clicking on it or clicking on toolbar’s Edit button, then the currently selected row will be changed to edited
        state. On the Chart side, you can edit the tasks using edit dialog by double clicking on the taskbars and you
        can edit the dependency connector lines using drag and drop action with connector line points available on the either side of taskbar.
    </p>
</ActionDescription>

<div class="col-lg-12 control-section">
    <div class="content-wrapper">
        <div class="row">
            <SfGantt DataSource="@TaskCollection" Height="450px" Width="100%" HighlightWeekends="true"
                     Toolbar="@(new List<string>(){ "Add", "Edit", "Update", "Delete", "Cancel", "ExpandAll", "CollapseAll","Indent","Outdent"})"
                     AllowSelection="true" GridLines="GridLine.Both" TreeColumnIndex="1"
                     ProjectStartDate="@ProjectStart" ProjectEndDate="@ProjectEnd">
                <GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Progress="Progress"
                                 Dependency="Predecessor" ParentID="ParentId" Notes="Notes"></GanttTaskFields>
                <GanttEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" AllowTaskbarEditing="true" ShowDeleteConfirmDialog="true"></GanttEditSettings>

                <GanttColumns>
                    <GanttColumn Field="TaskId" Width="100"></GanttColumn>
                    <GanttColumn Field="TaskName" HeaderText="Job Name" Width="250"></GanttColumn>
                    <GanttColumn Field="StartDate" HeaderText="Start Date"></GanttColumn>
                    <GanttColumn Field="EndDate" HeaderText="End Date"></GanttColumn>
                    <GanttColumn Field="Duration" HeaderText="Duration"></GanttColumn>
                    <GanttColumn Field="Progress" HeaderText="Progress"></GanttColumn>
                    <GanttColumn Field="Predecessor" HeaderText="Dependency"></GanttColumn>
                </GanttColumns>
                <GanttLabelSettings LeftLabel="TaskName" TValue="GanttData.TaskData">

                </GanttLabelSettings>
                <GanttSplitterSettings Position="30%"> </GanttSplitterSettings>
            </SfGantt>
        </div>
    </div>
</div>

@code{
    public DateTime ProjectStart = new DateTime(2019, 3, 25);
    public DateTime ProjectEnd = new DateTime(2019, 7, 28);
    public List<GanttData.TaskData> TaskCollection { get; set; }

    protected override void OnInitialized()
    {
        this.TaskCollection = GanttData.EditingData().ToList();

    }
}